package com.zboin.ucenter.service;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.zboin.ucenter.mapper.PermissionMapper;
import com.zboin.ucenter.model.Permission;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author zhboom
 * @date 2025/8/4 23:42
 */
@Service
public class PermissionServiceImpl implements PermissionService {

    private final PermissionMapper permissionMapper;

    public PermissionServiceImpl(PermissionMapper permissionMapper) {
        this.permissionMapper = permissionMapper;
    }

    @Override
    public Permission getPermissionById(Integer permitId) {
        return permissionMapper.selectById(permitId);
    }

    @Override
    public Permission getPermissionByKey(String permitKey) {
        return permissionMapper.selectOne(new QueryWrapper<Permission>().eq("permit_key", permitKey));
    }

    @Override
    public List<Permission> getPermissionByRoleId(Integer roleId) {
        return permissionMapper.getPermissionByRoleId(roleId);
    }

    @Override
    public int addPermission(Permission permission) {
        return permissionMapper.insert(permission);
    }

    @Override
    public int updatePermission(Permission permission) {
        return permissionMapper.updateById(permission);
    }

    @Override
    public int deletePermission(Integer permitId) {
        return permissionMapper.deleteById(permitId);
    }
}
